//
//  SLGlobalUI.swift
//  SkylowAPP
//
//  Created by 王王凤丽 on 2024/9/22.
//

import UIKit



// MARK: topVC
var topVC: UIViewController? {
    var resultVC: UIViewController?
    guard let appDelegate = UIApplication.shared.delegate as? AppDelegate else { return nil }
    resultVC = _topVC(appDelegate.window?.rootViewController)
    while resultVC?.presentedViewController != nil {
        resultVC = _topVC(resultVC?.presentedViewController)
    }
    return resultVC
}

private func _topVC(_ vc: UIViewController?) -> UIViewController? {
    if vc is UINavigationController {
        return _topVC((vc as? UINavigationController)?.visibleViewController)
    } else if vc is UITabBarController {
        return _topVC((vc as? UITabBarController)?.selectedViewController)
    } else {
        return vc
    }
}
